/*
by tonydon
 */

package txdnet.db;

import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import txdnet.util.Logger;

/**
 * @author txdnet
 */
public class JndiPool {
    
    private static String refname = null;
    private static Context ctx = init();
    
    
    private JndiPool(){}

    public static Connection getConnection() throws Exception {
   return ((DataSource)(((Context)ctx.lookup("java:comp/env")).lookup(refname))).getConnection();
    }

    private static Context init()
    {
        Context initCtx = null;
    try{
        initCtx = new InitialContext();
         refname = PoolFactory.getDbProperties().getProperty("jndi.refname");
     }catch(Exception e){
            initCtx = null;
            Logger.error(JndiPool.class, e.toString());
        }
        return initCtx;
    }
}